package com.kede.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kede.domain.StoreUserOrderDomain;
import com.kede.ienum.store.UserStoreStatusEnum;
import com.kede.service.StoreUserOrderService;
import com.kede.mapper.StoreUserOrderMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 11856
* @description 针对表【t_store_user_order(用户到门店消费物资记录表)】的数据库操作Service实现
* @createDate 2023-06-07 16:32:19
*/
@Service
public class StoreUserOrderServiceImpl extends ServiceImpl<StoreUserOrderMapper, StoreUserOrderDomain>
    implements StoreUserOrderService{

    @Override
    public int getBuyedNumBySupplieIdAndUserId(Integer supplieId, Integer userId) {

        LambdaQueryWrapper<StoreUserOrderDomain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StoreUserOrderDomain::getSupplieId,supplieId);
        queryWrapper.eq(StoreUserOrderDomain::getUserId,userId);
        queryWrapper.and(wrapper -> {
            wrapper.eq(StoreUserOrderDomain::getStatus, UserStoreStatusEnum.FINISH.getCode())
                    .or()
                    .eq(StoreUserOrderDomain::getStatus,UserStoreStatusEnum.RECEVE.getCode())
                    .or()
                    .eq(StoreUserOrderDomain::getStatus,UserStoreStatusEnum.WATI.getCode());
        });
        List<StoreUserOrderDomain> list = list(queryWrapper);
        Integer cout = 0;
        for (StoreUserOrderDomain storeUserOrderDomain : list) {
            cout += storeUserOrderDomain.getNum();
        }
        return cout;
    }
}




